home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / TEST / COORD_TR.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  3.0 KB  |  105 lines

  1.  
  2. package sub_arctic.test;
  3.  
  4. import sub_arctic.lib.base_interactor;
  5. import sub_arctic.lib.manager;
  6. import sub_arctic.output.drawable;
  7. import java.awt.Color;
  8. import java.awt.Font;
  9. import java.awt.FontMetrics;
  10. import java.awt.Point;
  11.  
  12. /** Demo class which displays its own location within a string */
  13. public class coord_tracker extends base_interactor {
  14.   /* instance variables */
  15.  
  16.   /** Text to show before the coordinate display */
  17.   protected String      _tag1 = "";
  18.  
  19.   /** Text to show after the coordinate display */
  20.   protected String      _tag2 = "";
  21.  
  22.   /** Text of the coordinate */
  23.   protected String      _coord_str = "";
  24.  
  25.  
  26.   /** Font to display in */
  27.   protected Font        _drawing_font;
  28.  
  29.   /** Cached metrics of the font */
  30.   protected FontMetrics _metric;
  31.  
  32.   /** Full constructor */
  33.   public coord_tracker(int xv, int yv, String tag_1, String tag_2, Font in_fnt) 
  34. {
  35.       super(xv,yv);
  36.  
  37.       /* set tags from paramters */
  38.       _tag1 = tag_1; _tag2 = tag_2; _coord_str = "?,?";
  39.  
  40.       /* use a default font if none was given */
  41.       if (in_fnt == null) in_fnt = new Font("Helvetica", Font.PLAIN, 24);
  42.  
  43.       /* establish a font and cache metrics object */
  44.       _drawing_font = in_fnt;
  45.       _metric = manager.get_metrics(_drawing_font);
  46.  
  47.       /* establish the size of the object */
  48.       set_intrinsic_h(_metric.getHeight()+4);
  49.       set_intrinsic_w(_metric.stringWidth(_tag1+_coord_str+_tag2)+4);
  50.  
  51.       /* force object to be reconfigured and redrawn */
  52.       damage_self();
  53.     }
  54.  
  55.   /** Constructor with default font */
  56.   public coord_tracker(int xv, int yv, String tag_1, String tag_2) 
  57. {
  58.       this(xv,yv,tag_1,tag_2,null);
  59.     }
  60.  
  61.   /** Constructor with all defaults */
  62.   public coord_tracker() 
  63. {
  64.       this(0,0,"[","]");
  65.     }
  66.  
  67.  
  68.   /** Tell the system that the object determines its own width & height */
  69.   public int intrinsic_constraints() {return W|H;}
  70.  
  71.   /** Recompute object's display string based on its new position & resize */
  72.   public void configure()
  73.     {
  74.       Point global_loc = local_to_global(0,0);
  75.       _coord_str = Integer.toString(global_loc.x) + "," + 
  76.     Integer.toString(global_loc.y);
  77.       set_intrinsic_w(_metric.stringWidth(_tag1+_coord_str+_tag2)+4);
  78.       super.configure();
  79.     }
  80.  
  81.   /** Provide drawing behavior for the object */
  82.   protected void draw_self_local(drawable d)
  83.     {
  84.       d.setColor(Color.black);
  85.       d.setFont(_drawing_font);
  86.       d.drawString(_tag1+_coord_str+_tag2, 2, _metric.getAscent()+2);
  87.     }
  88. };
  89. /*=========================== COPYRIGHT NOTICE ===========================
  90.  
  91. This file is part of the subArctic user interface toolkit.
  92.  
  93. Copyright (c) 1996 Scott Hudson and Ian Smith
  94. All rights reserved.
  95.  
  96. The subArctic system is freely available for most uses under the terms
  97. and conditions described in 
  98.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  99. and appearing in full in the lib/interactor.java source file.
  100.  
  101. The current release and additional information about this software can be 
  102. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  103.  
  104. ========================================================================*/
  105.